<!doctype html>
<html>
<head>
   <title>读取并解析csv</title>
</head>
<body>
<div>
    显示进度：
    <progress id="pro" value="0"></progress>
</div>
<div id="result"></div>

<script type="text/javascript">
	var file1 = document.getElementById('file1');
	file1.onchange = function () {
		var file = file1.files[0];
		//读取为二进制
		var reader = new FileReader();
		reader.readAsText(file,'utf-8');
		//显示进度
		var pro = document.getElementById('pro');
		pro.max = file.size;
		pro.value = 0;
		reader.onprogress = function (e) {
			pro.value = e.loaded;
		}
		reader.onload = function () {
			var str = reader.result;
			var rows = str.split('\n'); 
			/*var clients = [];
			for(var i =0; i<rows.length; i++){
				var row =rows[i].split(',') ;
				var client = {
					id:row[0],
					company:row[1],
					address:row[2],
					name:row[3],
					phone:row[4],
					coord:{x:row[5],y:row[6]}
				};
				clients.push(client);
			}
			//由对象转为JSON字符串
			console.log(JSON.stringify(clients));
            document.getElementById('result').innerHTML = JSON.stringify(clients);
			*/
			console.log(rows);
            document.getElementById('result').innerHTML = rows;
		}
	}
</script>
</body>
</html>
————————————————
版权声明：本文为CSDN博主「过重的背包」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/qq_34548699/article/details/105707859